package com.amado.course35Concurrent;

import java.util.Scanner;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

/**
 * 单向,通过ReentrantLock实现锁机制，AtomicInteger实现数量的控制（+1，-1）
 * @author Administrator
 *
 */
public class S10LinkedBlockingQueueTest {
	public static void main(String[] args) {
		LinkedBlockingQueue<Integer> queue = new LinkedBlockingQueue<>();
		new Thread(new Runnable() {
			@Override
			public void run() {
				while(true) {
					try {
						Integer value = queue.take();
//						Integer value = queue.poll(1,TimeUnit.SECONDS);
						System.out.println("从对列中获取到值" + value);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			}
		}).start();
		while(true){
			Scanner scanner = new Scanner(System.in);
			System.out.println("往队列中输入整数");
			queue.add(scanner.nextInt());
		}
	}

}
